package Texas.Console;
import java.util.*;

public class ConsoleMenu {
	private static Scanner _scanner = new Scanner(System.in);
	
	
	public static int selectOne(ConsoleMenuItem cMI[]) {		
		int selection = -1;
		
		do {
			for(int i = 0; i < cMI.length; i++)
				System.out.printf("[ %d ] %s\n", cMI[i].getValue(), cMI[i].getName());
			System.out.printf("Ihre Wahl: ");
			if(_scanner.hasNextInt())
				selection = _scanner.nextInt();
			else
				_scanner.next();
		} while(selection < cMI[0].getValue() || selection > cMI[cMI.length-1].getValue());
		
		return selection;		
	}
	
	public static int getInt(String expression, int from, int to) {
		int i = from-1;
		
		do {
			System.out.printf("%s (%d - %d): ", expression, from, to);
			if(_scanner.hasNextInt())
				i = _scanner.nextInt();
			else
				_scanner.next();
		} while(i < from || i > to);
		
		return i;
	}
	
	public static String getString(String expression) {	
		System.out.printf("%s: ", expression);
		return _scanner.next();
	}
}
